---
category: Validator
created: '2020-04-19'
title: Check if a given integer is a prime number
updated: '2021-10-13'
---

**JavaScript version**

```js isPrime.js
const isPrime = (n) =>
    n > 1 &&
    Array(Math.floor(Math.sqrt(n)) - 1)
        .fill(0)
        .map((_, i) => i + 2)
        .every((i) => n % i !== 0);
```

**TypeScript version**

```ts isPrime.ts
const isPrime = (n: number): boolean =>
    n > 1 &&
    Array(Math.floor(Math.sqrt(n)) - 1)
        .fill(0)
        .map((_, i) => i + 2)
        .every((i) => n % i !== 0);
```
